package com.woniuxy.his.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.his.entity.Medicine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.his.vo.AllMedicine;
import com.woniuxy.his.vo.GuaHaoVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
public interface MedicineMapper extends BaseMapper<Medicine> {

    @Select("<script>" +
            "select * from medicine " +
            "<where> " +
            "<if test='productName!=null'>  " +
            "product_name   like concat('%',#{productName},'%') " +
            "</if>" +
            "</where>" +
            "</script>")
    IPage<Medicine> findByPage(IPage<Medicine> page, String productName);

    //添加处方表

    //获取病例ID
    @Select("select case_id from his_case where patient_id in (select patient_id from his_guahao where gua_id=#{guaId})")
    public Integer getCaseId(Integer guaId);

    //写入处方表
    @Insert("insert into his_prescription (case_id,prescription_price,doctor_id) values (#{caseId},#{totalMedicine},#{doctorId})")
    public Integer insertMedicine(Integer totalMedicine,Integer caseId,Integer doctorId);

    //添加处方详情表

    //获取药品ID
    //动态获取项目ID
    @Select("<script>select id from medicine where product_name in <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'>#{item}</foreach></script>")
    public List<Integer> getMedicineId(@Param("list") List<String> list);

    //获取处方ID
    @Select("select max(prescription_id) from his_prescription where case_id=#{caseId}")
    public Integer getPrescriptionId(Integer caseId);

    //写入检查详情表
    @Insert("insert into his_pres_detail (medicine_id,medicine_num,prescription_id) values (#{medicineId},#{num},#{prescriptionId})")
    public Integer insertHisPresDetail(Integer medicineId,Integer num,Integer prescriptionId);

    //获取药品库所有的数据信息
    @Select("select * from medicine")
    public IPage<AllMedicine> getAllMedicine(IPage<AllMedicine> page);








}
